<?php

/**
 * @deprecated
 * 2022年双11清单活动
 */
class GoodBuyAction extends ActionPlugin
{

    const USER_LEVEL = self::LEVEL_NOTHING;
    
    public function main()
    {
        $act = '';
        if ($params = $this->getRequest()->getParams()) {
            $act = key($params);
        }

        $params = $this->getRequest()->getPost();

        if ($params['action'] ?? '') $act = $params['action'];//home detail lottery create deliver share
        $activity = \Biz\service\activity\CreateWikiList::getInstance($this->uid, $this->did);

        $response = null;
        $act = strtolower($act);
        switch ($act) {
            case 'deliver':
                $name = $params['name'] ?? '';
                $phone = $params['phone'] ?? '';
                $address = $params['address'] ?? '';
                $award_id = $params['award_id'] ?? '';
                $phone = \Doraemon\model\Phone::addExtendPhone($phone,\hhz\constant\basic\UserExtendPhoneScene::ACTIVITY_CREATE_WIKI_LIST);
                $activity->receiveRecordCreate($award_id, $name, $phone, $address);
                break;
            case 'times':
                $share_task = $activity->getShareTaskMaxTimes() - $activity->getFinishShareTask();
                $create_task = $activity->getCreateTaskMaxTimes() - $activity->getFinishCreateTask();
                $response = [
                    'lottery_times' => $activity->getLotteryTimes(),
                    'share_task' => $share_task > 0 ? $share_task : 0,
                    'create_task' => $create_task > 0 ? $create_task : 0,
                ];
                break;
            case 'lottery':
                $response = $activity->lottery();
                break;
            case 'detail':
                $topic_id = $params['topic_id'] ?? 0;
                $page = $params['page'] ?? 1;
                $page_size = $params['page_size'] ?? 10;
                $sort_type = $params['sort_type'] ?? 1;
                $response = $activity->detail($topic_id, $sort_type, $page, $page_size);
                break;
            case 'share':
                $activity->finishShareTask();
                break;
            case 'create':
                $wiki = $params['wiki_id'] ?? 0;
                $msg = $params['msg'] ?? '';
                $topic_id = $params['topic_id'] ?? 0;
                $activity->createGuidance($topic_id, $wiki, $msg);
                break;
            default:
                $response = $activity->home();
                break;
        }
        $this->setSuccess($response);
    }
}